package com.vcredit.creditcat.web.app;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.dubbo.config.annotation.Reference;
import com.vcredit.creditcat.api.IAppTokenManager;
import com.vcredit.creditcat.api.ICustManager;
import com.vcredit.creditcat.api.ICustReportManager;
import com.vcredit.creditcat.model.CreditTipsShowVo;
import com.vcredit.creditcat.model.Cust;
import com.vcredit.creditcat.model.CustReportParam;
import com.vcredit.creditcat.model.CustReportVo;
import com.vcredit.creditcat.model.SesameScoreVo;
import com.vcredit.creditcat.vo.JsonResult;
import com.vcredit.framework.annotation.Log;

@RestController
@RequestMapping("/report")
public class CustReportController extends BaseCreditCatController {

	@Reference(version = "1.0")
	private ICustReportManager ICustReportManager;
	@Reference(version = "1.0")
	private IAppTokenManager appTokenService;

	@Reference(version = "1.0")
	private ICustManager custManager;
	private static Logger logger = LoggerFactory.getLogger(CustReportController.class);

	/**
	 * 信用分析 --报表
	 * 
	 * @param custReportParam
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@Log
	@RequestMapping("/reportAnalysis")
	public JsonResult<CustReportVo> reportAnalysis(@RequestBody CustReportParam custReportParam, HttpServletRequest request) throws Exception {
		Long custId = super.getCust(request).getCustId();
		CustReportVo vo = ICustReportManager.CustReoprtAnalysis(custId, custReportParam);

		return JsonResult.SuccessResponse(vo);
	}

	/**
	 * 信用贴士
	 * 
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@Log
	@RequestMapping("/creditTips")
	public JsonResult<CreditTipsShowVo> creditTips(HttpServletRequest request) throws Exception {

		String appDesc = request.getHeader("appDesc");
		String accessToken = request.getHeader("accessToken");
		Long custId = null;
		Cust cust = null;
		if (super.hasOnLine(request)) {
			custId = appTokenService.getCustIdFromToken(accessToken);
			cust = custManager.findById(custId);
		}
		return JsonResult.SuccessResponse(ICustReportManager.CustGradeAnalysis(cust, appDesc));
	}

	/**
	 * 芝麻分
	 * 
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@Log
	@RequestMapping("/sesameScore")
	public JsonResult<SesameScoreVo> sesameScore(@RequestBody Map<String, Object> paramMap,HttpServletRequest request) throws Exception {
		Cust cust = super.getCust(request);
		String ispull =  String.valueOf(paramMap.get("ispull"));
		return JsonResult.SuccessResponse(ICustReportManager.getSesameScoreVo(cust,ispull));
	}
}
